package com.t3go.t3_map;



import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.shareware.common.listener.Callback;
import com.shareware.common.utils.LogExtKt;

import java.util.HashMap;
import java.util.Map;

import io.flutter.plugin.common.MethodChannel;

public class FlutterMapPlugin {
    public static final String TAG = "FlutterMapPlugin";
    private static MethodChannel methodChannel;
    private static FlutterMapPlugin mapPlugin = new FlutterMapPlugin();

    public static void initMethodChannel(MethodChannel channel) {
        methodChannel = channel;
    }

    /**
     * 选择地址
     *
     * @param type 1:起点 2:终点
     */
    public static void selectAddress(int type, Callback<Object> callback) {
        LogExtKt.log(TAG, "选址开始 类型: " + (type == 1 ? "起点" : "终点"));
        Map<String, Object> args = new HashMap<>();
        args.put("type", type);
        methodChannel.invokeMethod("selectAddress", args, new MethodChannel.Result() {
            @Override
            public void success(@Nullable Object result) {
                LogExtKt.log(TAG, "选址结果success: ");
                callback.call(result);
            }

            @Override
            public void error(@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
                LogExtKt.log(TAG, "选址结果error: ");
                callback.call(null);
            }

            @Override
            public void notImplemented() {

            }
        });
    }

}
